<template>
  <div class="applyWrapper "style="background: white">
    <div class="contentWrapper">
      <div class="headWrapper " style="margin-bottom: 50px">
        <div class="btn">
          <button @click="do_submitUnit">提交增加申请</button>
        </div>
      </div >
      <!--表单================-->
        <div class="ActiveTitleWrapper" v-show="isRegist">
          <span class="title" >申请人：</span>
          <i class="resourceName resourceName1">
            <input type="text" class="input " v-model="userName">
          </i>
        </div>
        <div class="ActiveTitleWrapper" v-show="isRegist">
          <span class="title" >申请人电话：</span>
          <i class="resourceName resourceName1">
            <input type="text" class="input " v-model="userTel" disabled>
          </i>
        </div>


      <div class="ActiveTitleWrapper" >
        <span class="title">所属市州区县：</span>
        <i class="resourceName resourceName1" @click="do_addUnit">
          <input type="text" class="input_active input" v-model="formData.workUnit" readonly>
        </i>
      </div>

      <div class="ActiveTitleWrapper">
        <span class="title" >单位名称：</span>
        <i class="resourceTitle">
          <input type="text" class="input" v-model="addWorkName">
        </i>
      </div>
      <div class="ActiveTitleWrapper">
        <span class="title">说明：</span>
        <i class="resourceTitle">
          此功能用于用户在选择单位时系统中无此单位，需增加单位的基础设置，由用户提出增加申请,由区县，市州，省级管理员确认后增加。
        </i>
      </div>
      <div class="filesUp" >
        <div style="height: 30px">
          <span class="title1" style="top: -10px" >申请历史：</span>
          <div class="filesWrapper" >
            <span class=" text-center" v-for="(item,index) in unitData " :key="index" v-text="item.title"></span>
          </div>
        </div>
        <div style="height: 30px" v-if="true" v-for="(unitData,index) in unitDataAll" :key="index">
          <span class="title1"></span>
          <div class="filesWrapper filesWrapper2" style="border-top: 1px solid white;height: 30px" >
            <span class="text-center" v-for="(item,index) in unitData " :key="index"  v-text="item.text"
            style="background-color: #ebf3f9;white-space: nowrap;text-overflow: ellipsis;overflow: hidden" :title="item.text"
            ></span>
          </div>
        </div>
      </div>
    </div>
    <cmAddUnit v-if="unitShow" @Unit="do_getUnit($event)" @do_close="do_close"></cmAddUnit>
    <transition name="fade">
      <cmCofirm
        title="错误"
        confirm="确定"
        :msg=mistakeMsg
        @confirm1="def_confirm($event)"
        v-if="mistake"
      >
      </cmCofirm>
    </transition>
  </div>
</template>

<script>
  import cmAddUnit from './common/cmAddUnit'
  import cmCofirm from './common/cmCofirm'
    export default {
        name: "bsAppendUnit.vue",
      components:{
        cmAddUnit,
        cmCofirm
      },
      data(){
      return{
        mistake:false,
        mistakeMsg:'',
        isRegist:false,
        unitShow:false,
        unitDataAll:[],
        unitData:[
          {title:'申请时间',text:'无'},
          {title:'单位名称',text:'无'},
          {title:'区县',text:'无'},
          {title:'州市',text:'无'},
          {title:'处理时间',text:'无'},
          {title:'结果',text:'无'},
          {title:'说明',text:'无'},
        ],
        formData:[
          {workUnit:''},
          {workUnitSN:''},
          {CitySN:''}
        ],
        addWorkName:'',
        userName:'',
        userTel:'',
      }
      },
      created(){
          try {
            let me=this;
            let addunit= localStorage.getItem('addUnit');
            if(addunit=='isRegist'){
              me.userTel= localStorage.getItem('userTel');
              me.isRegist=true

            }if(addunit=='isApplyDetail'){
              me.userTel=localStorage.getItem("tel")
              me.isRegist=false
              me.$ZcPublic.UserId= localStorage.getItem('UserId');
            }
            me.$ZcPublic.Server.Post({
              IsNeedLogin:'false',
              Paras:{
                //UserId:me.$ZcPublic.UserId,
                Name: 'Vue_CustomerResource',
                Action: 'Ext_ApplyByRegPhone',
                Data:{
                  RePhone: me.userTel
                }
              },
              Callback:me.cb_Ext_ApplyByRegPhone,
              Scope:me
            });
          }catch (e) {

          }
      },
      methods:{
        def_confirm(){
          this.mistake=false
        },
        do_addUnit(){
          this.unitShow=true
        },

        do_getUnit(data){
          this.unitShow=false;
          console.log(data);
          this.formData.workUnit=data.workUnit;
          this.formData.workUnitSN=data.workUnitSn
          this.formData.CitySN=data.CitySN
        },
        do_close(){
          this.unitShow=false
        },
        do_submitUnit(){
          try {
            let addUnitName=this.formData.workUnit.split('-')[0]
            let DistrictName=this.formData.workUnit.split('-')[1]
            let me=this;
            if(localStorage.getItem('addUnit')=="isApplyDetail"){
              me.$ZcPublic.Server.Post({
                IsNeedLogin:'false',
                Paras:{
                  //UserId:me.$ZcPublic.UserId,
                  Name:'Vue_CourseResource',
                  Action:'Ext_WorkUnitSubmit',
                  Data:{
                    Name:me.addWorkName,
                    CitySN:me.formData.CitySN,
                    CityName:addUnitName,
                    DistrictSN:me.formData.workUnitSN,
                    DistrictName:DistrictName,
                    //ApplyMan:me.userName,
                    //UserRegPhone:me.userTel
                  }
                },
                Callback:me.cb_WorkUnitSubmit,
                Scope:me
              });
            }else {
              me.$ZcPublic.Server.Post({
                IsNeedLogin:'false',
                Paras:{
                  //UserId:me.$ZcPublic.UserId,
                  Name:'Vue_CourseResource',
                  Action:'Ext_insertWorkUintAddApply',
                  Data:{
                    Name:me.addWorkName,
                    CitySN:me.formData.CitySN,
                    CityName:addUnitName,
                    DistrictSN:me.formData.workUnitSN,
                    DistrictName:DistrictName,
                    ApplyMan:me.userName,
                    UserRegPhone:me.userTel
                  }
                },
                Callback:me.cb_WorkUnitSubmit,
                Scope:me
              });
            }

          }catch (e) {

          }

        },
        /*============回调======*/
        cb_WorkUnitSubmit(resJson,scope){
          console.log('提交单位返回')
          console.log(resJson)
          if(resJson.success==true){
            this.$router.go(0)
          }else {
            this.mistake=true;
            this.mistakeMsg=resJson.msg
          }
        },
        cb_ReBind(resJson,scope){
          console.log(resJson)
        },
        cb_Ext_ApplyByRegPhone(resJson,scope){
          console.log('已经提交的单位')
          console.log(resJson)

        if(!resJson.success){
            this.mistake=true;
            this.mistakeMsg=resJson.msg
        }else {
          // resJson.data.forEach((historyData)=>{
          for(let i=0;i<resJson.data.length;i++){
            let unitData2=[{text:''},{text:''},{text:''},{text:''},{text:''},{text:''},{text:''}]
            unitData2[0].text=this.Test(resJson.data[i].ApplyDate)
            unitData2[1].text=resJson.data[i].Name
            unitData2[2].text=resJson.data[i].DistrictName
            unitData2[3].text=resJson.data[i].CityName
            unitData2[4].text=this.Test(resJson.data[i].doDate)
            if(unitData2[4].text=='1950-4-24'){
              unitData2[4].text=''
            }
             unitData2[5].text=resJson.data[i].Result
             unitData2[6].text=resJson.data[i].doRemark
            this.unitDataAll.push(unitData2)
          }
          console.log(88888)
          console.log(this.unitDataAll)
        }
        },
        /*转化时间格式*/
        formatDate(dt) {
          let year = dt.getFullYear();
          let month = dt.getMonth() + 1;
          let date = dt.getDate();
          return year + "-" + month + "-" + date
        },
        Test(time) {
          let t= time.slice(6, 19);
          let NewDtime = new Date(parseInt(t));
          return this.formatDate(NewDtime);
        },
      }
    }
</script>

<style scoped>
  *{
    font-size: 14px;
  }
  .title{
    display: inline-block !important;
    width: 136px !important;
    height: 46px !important;
    text-align: right !important;
  }
  .applyWrapper{
    width: 100%;
  }
  .applyWrapper .contentWrapper{
    width: 1080px;
    margin: 0 auto;
    border: 1px solid gainsboro;
    /*height: 500px;*/
    padding: 5px;
  }
  .headWrapper{
    position: relative;
    height: 40px;
    border-bottom: 1px solid gainsboro;
    line-height: 40px;
  }
  .headWrapper .btn{
    position: absolute;
    left: 0px;
    /*width: 150px;*/
    /*background-color: gainsboro;*/
  }
  .headWrapper .btn button{
    background-image: url(../assets/footImg2019-4-30.png);
    background-size: 100% 100%;
    padding: 5px 20px;
    font-size: 15px;
    color: #fff;
    border-radius: 2px;
    border: none;
    cursor: pointer;
    position: relative;
    top: -5px;
  }
  .headWrapper .btn button:first-child{
    margin-right: 10px;
  }

  .ActiveTitleWrapper{
    line-height: 46px;
    position: relative;
    text-align: center;
  }
  .resourceName{
    height: 46px;
  }
  .resourceName1{
    display: inline-block;
    height: 46px;
    width: 508px;
  }
  .input{
    width: 100%;
    height: 30px;
    line-height: 30px;
    border: 1px solid #91a8c9
  }
  .resourceTitle{
    display: inline-block;
    height: 46px;
    width: 508px;
  }
  .ActiveTitleWrapper:last-child{
    position: relative;
  }
  .ActiveTitleWrapper:last-child>span{
    position: relative;
    top: -19px;
  }
  .resourceTitle:last-child{
    font-style:normal;
    height: 46px;
    line-height: 20px;
    text-align: left;
    color: red;

  }

  .filesWrapper{
    display: inline-block;
    width: 868px;
    /*border:1px solid #91a8c9 ;*/
    /*background-color: #127cc0;*/
  }
  .filesWrapper span{
    float: left;
    height: 30px;
    line-height: 30px;
width: 124px;
    border-right: 1px solid white;
    color: white;
  }
  .filesWrapper2 span{
    color: black;
  }
  .filesUp{
    position: relative;
    height: 200px;
  }
  .filesUp div:nth-child(1)>div{
    background-color:#127cc0;;
  }
  .filesUp div:nth-child(2)>div{
    background-color: #ebf3f9
  }

  .filesUp .title1{
    position: relative;
    display: inline-block ;
    width: 136px ;
    height: 30px ;
    line-height: 30px;
    text-align: right;
    top: 0px;
  }
  /*.filesUp .title1:first-child{*/
    /*top: 0;*/
  /*}*/
  .input_active{
    background: url('../assets/icon_center22019-5-6.png') 98% center no-repeat;
  }
  /*彈出框*/
  .fade-enter-active {
    transition: opacity .6s;
  }
  .fade-leave-active{
    transition: opacity .1s;
  }
  .fade-enter, .fade-leave-to {
    opacity: 0;
  }
  .fade-enter-to, .fade-leave {
    opacity: 1;

  }
</style>
